﻿using MicroBlog.Areas.Admin.ViewModels;
using MicroBlog.Infrastructure;
using MicroBlog.Models;

namespace MicroBlog.Services
{
    /// <summary>
    /// 用户管理接口
    /// </summary>
    public interface IUserManager
    {
        #region 登录/退出 相关方法
        /// <summary>
        /// 登录系统
        /// </summary>
        /// <param name="httpContext"><see cref="HttpContext"/></param>
        /// <param name="userName">验证的值</param>
        /// <param name="secret">密码</param>
        /// <param name="isPersistent">是否记住</param>
        Task<ContextResult> SignInAsync(HttpContext httpContext, string userName, string secret, bool isPersistent = false);
        /// <summary>
        /// 退出系统
        /// </summary>
        /// <param name="httpContext"></param>
        Task SignOutAsync(HttpContext httpContext);
        #endregion

        #region 增删改查
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="userName">名称</param>
        /// <param name="secret">密码</param>
        /// <returns><see cref="ContextResult"/></returns>
        Task<ContextResult> CreateAsync(string userName, string secret);
        /// <summary>
        /// 添加角色
        /// </summary>
        /// <param name="role"></param>
        /// <returns></returns>
        Task<ContextResult> CreateRoleAsync(Role role);
        /// <summary>
        /// 根据用户名查找用户信息
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <returns>查找成功返回用户信息，否则返回null</returns>
        Task<User> FindByNameAsync(string userName);
        /// <summary>
        /// 删除指定的用户
        /// </summary>
        /// <param name="id">用记ID</param>
        /// <returns></returns>
        Task<ContextResult> RemoveAsync(int id);
        /// <summary>
        /// 把指定用户添加到指定角色中
        /// </summary>
        /// <param name="userId">用户的ID</param>
        /// <param name="roleName">角色的名称</param>
        /// <returns></returns>
        Task<ContextResult> AddToRole(int userId, string roleName);
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="userId">用户ID</param>
        /// <param name="oldSecret">老密码</param>
        /// <param name="secret">新密码</param>
        /// <returns></returns>
        Task<ContextResult> ChangeSecret(int userId, string oldSecret, string secret);

        /// <summary>
        /// 获取当前用户的ID
        /// </summary>
        /// <param name="httpContext">Http请求对象<see cref="HttpContext"/></param>
        /// <returns>找到返回梁用的ID，否则返回-1</returns>
        int GetCurrentUserId(HttpContext httpContext);
        /// <summary>
        /// 获取当前用户信息
        /// </summary>
        /// <param name="httpContext">Http请求对象<see cref="HttpContext"/></param>
        /// <returns>查找成功返回用户信息，否则返回null</returns>
        Task<UserModel> GetCurrentUser(HttpContext httpContext);

        #endregion
    }
}
